package collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

//数组转集合
public class ArrayToList {
    public static void main(String[] args) {
        String[] str={"one","two","three","four","five"};
        System.out.println(Arrays.toString(str));//[one, two, three, four, five]

        List<String> list=Arrays.asList(str);
        System.out.println(list);//[one, two, three, four, five]

        //改变数组中的元素,集合也会跟着改变,反之同理;
        str[1]="six";
        System.out.println(Arrays.toString(str));//[one, six, three, four, five]
        System.out.println(Arrays.toString(str));//[one, six, three, four, five]

        list.set(2,"seven");
        System.out.println(list);
        System.out.println(Arrays.toString(str));




        //给集合添加/删除元素相当于给数组添加/删除元素
        //而数组是定长的,不会自动扩容/缩容,因此不支持操作异常
        //list.add("!!!!");//输出异常

    }
}
